Lesson: 14 - Nested Loops

Purpose :Students learn the concept of nested loops.

Materials Required

Scratch 3.0

Curriculum Content 5.4) Loops
Prior knowledge

Knowledge of directions and countings

Exercises

Exercise:1



  1. Write a code to find prime numbers from 2 to 50.


See the video for your reference.

Solutions



  • Click here to view the sb3 file to complete the exercise-1. (Solution).

  • Teacher's Instruction
    1. Emphasise that any control block can be inside any other. i.e. repeat inside another repeat, repeat inside if-then, if-then inside repeat, etc.
    2. Points to Ponder: When looking for prime numbers, the second loop does not need to run till the desired number. Ask the students to think about where it can stop. I.e. If it is a composite number, it has to have a factor less than _____. They may first come up with N/2. You can point out that there has to be a factor less than sqrt(N).
    3. For both the options, you can ask the students to think about how many steps this program will take to check if a number is a prime.